﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace DLL.UploadFile
{
	/// <summary>
	/// 视图控制类
	/// </summary>
	/// <![CDATA[2014-8-7 17:52:59]]>
	public class View : DLL.ShowLayer.FormView
	{
		private Component clsthisComp;
		private string strWebColumnIDs = "";		// 用户有权限的前台栏目

		/// <summary>
		/// 用户有权限的前台栏目
		/// </summary>
		/// <![CDATA[2014-8-17 16:50:19]]>
		/// <![CDATA[2014-8-17 16:50:16]]>
		public string WebColumnIDs
		{
			get { return strWebColumnIDs; }
			set { strWebColumnIDs = value.Trim(); }
		}

		#region 添加、修改
		private TextBox tbDate = new TextBox();
		private FileUpload fUpload = new FileUpload();
		private CheckBoxList cblWebColumn = new CheckBoxList();
		#endregion 添加、修改

		#region 查询

		#endregion 查询

		#region 浏览

		#endregion 浏览

		#region 构造函数
		/// <summary>
		/// 视图类构造函数
		/// </summary>
		/// <![CDATA[2014-8-17 14:51:14]]>
		public View(System.Web.UI.Page page)
			: base(page)
		{
			clsthisComp = new Component(page);

			clsComp = clsthisComp;
			tbDate.Text = System.DateTime.Now.ToShortDateString();
			tbDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("栏目", "CheckBoxList", cblWebColumn, "", ""));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("时间", "TextBox", tbDate, "string", "strDate"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("文件", "FileUpload", fUpload, "", ""));
		}
		#endregion 构造函数

		#region 类型转换

		protected override TonyNet4V1.EntityBase GetEntity()
		{
			return new Entity();
		}

		protected override TonyNet4V1.QueryEntityBase GetQuery()
		{
			return new QueryEntity();
		}

		protected override TonyNet4V1.ComponentBase GetComponent()
		{
			return clsthisComp;
		}

		#endregion 类型转换

		public override void Init()
		{
			base.Init();

			clsControls.ShowHaveRightWebColumn(strWebColumnIDs, cblWebColumn);
		}

		public override void ShowRead()
		{
			//base.ShowRead();
			TonyNet4V1.ShowMessageAlert.ShowMessage(clsPage, "123");
		}

		/// <summary>
		/// 添加
		/// </summary>
		/// <returns></returns>
		public override bool Add()
		{
			bool bAdd = true;

			if (cblWebColumn.Items.Count > 0)
			{
				for (int i = 0; i < cblWebColumn.Items.Count; i++)
				{
					if (cblWebColumn.Items[i].Selected == true)
					{

						Entity clsEntity = new Entity();

						clsEntity.Date = tbDate.Text;
						clsEntity.WebColumnID = Convert.ToInt32(cblWebColumn.Items[i].Value);
						clsEntity.UserID = nUserID;
						clsEntity.DepartmentID = nDepartmentID;
						if (clsthisComp.Add(clsEntity, fUpload))
						{

						}
						else
						{
							bAdd = false;
						}
					}
				}

				if (bAdd)
				{
					TonyNet4V1.ShowMessageAlert.ShowMessage(clsPage, "文件上传成功！");
					return true;
				}
				else
				{
					TonyNet4V1.ShowMessageAlert.ShowMessage(clsPage, "文件上传失败！");
					return false;
				}
			}
			else
			{
				TonyNet4V1.ShowMessageAlert.ShowMessage(clsPage, "请选择栏目！");
				return false;
			}

			//return base.Add();
		}

		/// <summary>
		/// 用GridView显示登录用户所在单位所有上传的文件
		/// </summary>
		/// <param name="gv"></param>
		public void ShowMySeflDepartmentFile(GridView gv)
		{
			gv.DataSource = clsthisComp.QueryByDepartmentIDs(nDepartmentID.ToString());
			gv.DataKeyNames = new string[] { "ID" };
			gv.DataBind();
		}
	}
}
